home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-08 | 4.3 KB | 77 lines | [TEXT/CWIE] |
- class LDynamicPopupMenu v 1.0
- 1/8/95 written by Constantine Spathis
-
- What it does:
- This class creates a dynamic pop-up menu from a stream in a PPob resource, it disregards
- the menu id you specify in the PPob popupmenu field and instead it creates a menu with ID
- starting at 20000 and increments upwards from there. (NOTE: You must make sure that the
- number you pick is far from the numbers of any other possible menus, I suggest that they
- be below the menu id's you use for your dynamic pop-ups)
-
- Why is it needed:
- The problem is that in powerplant when using the (PPob) stream based constructors you
- must specify the menu_ID of the popup menu you want to create. You unfortunately won't
- know the menuid until runtime and then all pop-ups read in from that particular ppob are
- connected to that one menu and when one goes away all go away. An example may help to
- explain the problem better.
-
- Suppose your program uses Windows that have pop-up menus in them. Since you are supporting
- multiple windows created from the same PPob all will work well, except when you want to add
- a menu item to one of the windows only. Because of the Control Manager/Menu Manager
- structure the item will be added to all the pop-up menu's because all the pop-up menu's
- point to the same MenuHandle. Even worse when you close one window it disposes of the pop-up
- control and the Control Manager disposes of the Menu. That menu no-longer exists and when
- the control in another window goes to re-draw the menu the mac will likely crash because
- the menu was disposed of when the earlier control was disposed. The way LDynamicPopupMenu
- gets around this is to disregard the control PowerPlant made (it disposes of it so you
- don't get a memory leak) and to first create a NewMenu with a unique menu id, insert that
- menu into the menu list and recreate the control, making sure that text traits are taken
- care of properly.
-
- How to use it:
- First register the stream based creator function in the app constructor by:
- URegistrar::RegisterClass('LDPM',
- (ClassCreatorFunc) LDynamicPopupMenu::CreateLDynamicPopupMenuStream);
-
- In your PPob create the pop-up menu exactly the way you want it to appear (including text
- traits) and alias it to class type 'LPDM'. Also in the Menu id field specify a menu resource
- and make a menu of that resource number, it doesn't have to contain any items though.
- I generally title these as stubs.
-
- Then after the menu is created (either by a direct call or because it was in a window)
- begin adding Items to the menu using the member functions:
- AddPMenuItem(pstr) or
- AddCMenuItem(cstr)
- I hate translating between pascal & c strings so these do it. If the item you want to add
- to the menu is a c string call the member function AddCMenuItem passing it a c-string, if
- instead the item you want to add to the menu is a pascal string call the member function
- AddPMenuItem passing it a pascal string.
-
- After you are finished adding menu items it is crucial that you call the member function:
-
- FinishedCreatingMenu(Int32 in_initialItem) // Initial Menu Item to show
-
- It puts stuff right, the parameter to pass is the number of the item you want displayed.
- You can still add and modify items after this but call it before the menu gets drawn. If
- you notice that the menu is coming up blank but when you mouse down the menu is correct
- you probably forgot to call this member function.
-
- You'll probably want to modify the included BroadcastValueMessage in the LDynamicPopupMenu
- class it does really bad things now for the demo program included.
-
- Note this class LDynamicPopupMenu is derived from LStdPopupMenu and you can call whatever member
- functions you could call in LStdPopupMenu.
-
- Who is Responsible:
- Not me, this is total freeware, no rights are reserved, use it and abuse it at will. If you find
- bugs or if you come up with some cool modifications I would love to hear about them.
- I have tested this stuff and all appears well though.
-
- Who to thank:
- Greg Dow for coming up with such a nifty framework, Ron Liechty (hope I spelled that one
- correct) who must really be 10 guys from the way he keeps ontop of answering questions,
- and of course all the gang at Metrowerks for the coolest compilers (not to mention geekware).
-
-
- Constantine Spathis
- MadHack@aol.com